package com.lhkj.ct.meta.modules.gauge.validation;

import com.lhkj.ct.meta.modules.gauge.common.enums.QuestionType;
import com.lhkj.ct.meta.modules.gauge.model.entity.TblGaugeQuestion;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *     题目校验
 * </p>
 */
public class QuestionGroupSequenceProvider implements DefaultGroupSequenceProvider<TblGaugeQuestion> {

    @Override
    public List<Class<?>> getValidationGroups(TblGaugeQuestion question) {
        List<Class<?>> defaultGroupSequence = new ArrayList<>();
        // warn 这一步不能省,否则Default分组都不会执行，会抛错
        defaultGroupSequence.add(TblGaugeQuestion.class);
        if (question != null) {
            // 单选和多选必须设置选项
            if (null != question.getType() && (question.getType() == QuestionType.radio || question.getType() == QuestionType.checkbox)) {
                defaultGroupSequence.add(TblGaugeQuestion.option.class);
            }
        }
        return defaultGroupSequence;
    }
}
